package com.amtf.datafile2.cfg.txt;

import com.amtf.datafile2.cfg.std.StdDataTableDefinition;
import com.amtf.datafile2.core.txt.TxtDataRecord;

public class TxtDataTableDefinition extends StdDataTableDefinition<TxtDataFieldDefinition> {
	public static enum PARSE_MODE {
		// 定义为主，设置的row列数大于定义时 忽略row
		DEFINITION_PRIORITY,
		// 源Row为主，设置的row列数大于定义时 扩充定义
		SOURCE_PRIORITY, INTERSECTIONS_PRIORITY
	}

	private char fieldDelimiter = ',';
	private char smartQuote = '"';
	private String rowTerminator = "\r\n";
	private String encoding = "UTF-8";
	private PARSE_MODE parseMode = PARSE_MODE.DEFINITION_PRIORITY;

	public TxtDataTableDefinition(String name) {
		super(name, TxtDataRecord.class);
	}

	@Override
	public TxtDataTableDefinition clone() {
		TxtDataTableDefinition cloneDef = new TxtDataTableDefinition(name, "UTF-8", false, false, ',', '"', PARSE_MODE.DEFINITION_PRIORITY);

		copyTo(cloneDef);
		cloneDef.fieldDelimiter = this.fieldDelimiter;
		cloneDef.smartQuote = this.smartQuote;
		cloneDef.rowTerminator = this.rowTerminator;
		cloneDef.encoding = this.encoding;
		cloneDef.parseMode = this.parseMode;
		return cloneDef;
	}

	public TxtDataTableDefinition(String name, String encoding, boolean firstRowTitle, boolean titleAsColumnName, char fieldDelimiter, char smartQuote, PARSE_MODE parseMode) {
		this(name);
		this.fieldDelimiter = fieldDelimiter;
		this.smartQuote = smartQuote;
		this.encoding = encoding;
		this.firstRowTitle = firstRowTitle;
		this.titleAsColumnName = titleAsColumnName;
		this.parseMode = parseMode;
	}

	@Override
	public TxtDataRecord newDataRecordInstance() {
		return new TxtDataRecord(this);
	}

	@Override
	protected TxtDataFieldDefinition newDataFieldDefinition(String columnName) {
		return new TxtDataFieldDefinition(columnName);
	}

	public char getFieldDelimiter() {
		return fieldDelimiter;
	}

	public char getSmartQuote() {
		return smartQuote;
	}

	public void setSmartQuote(char smartQuote) {
		this.smartQuote = smartQuote;
	}

	public String getRowTerminator() {
		return rowTerminator;
	}

	public void setRowTerminator(String rowTerminator) {
		this.rowTerminator = rowTerminator;
	}

	public String getEncoding() {
		return encoding;
	}

	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}

	public void setFieldDelimiter(char fieldDelimiter) {
		this.fieldDelimiter = fieldDelimiter;
	}

	public PARSE_MODE getParseMode() {
		return parseMode;
	}

	public void setParseMode(PARSE_MODE parseMode) {
		this.parseMode = parseMode;
	}

}
